package edu.berkeley.guir.webquilt.proxy;

import edu.berkeley.guir.webquilt.*;

/**
 * This is a wrapper class which contains all the necessary
 *  variables for the proxying of a single document and then
 *  logging the transaction. As it is just a wrapper, all
 *  variables are of type 'public' allowing easy access and
 *  modification of the data from any other WebQuilt class.
 *  There are also a number of helper methods for generating
 *  log file names, etc.
 *
 * <P>
 * This software is distributed under the
 * <A HREF="http://guir.cs.berkeley.edu/projects/COPYRIGHT.txt">
 * Berkeley Software License</A>.
 *
 * <PRE>
 * Revisions:  - WebQuilt-v1.0-2.0.0, Mar 10 2001, jheer
 *               Created class
 *             - WebQuilt-v2.0.0-2.0.1 Dec 28 2001, kaow
 *               Added strTaskBox field
 *             - WebQuilt Apr 15 2002, kaow
 *               Added support for interdeck WAP logging
 * </PRE>
 *
 * @author  Jeffrey Heer (
 *          <A HREF="mailto:jheer@hkn.eecs.berkeley.edu">jheer@hkn.eecs.berkeley.edu</A>
 *          )
 * @author  Wayne Kao (
 *          <A HREF="mailto:kaow@cs.berkeley.edu">kaow@cs.berkeley.edu</A>
 *          )
 * @since   JDK 1.3
 * @version WebQuilt-v2.0.0-2.0.1, Dec 28 2001
 *
 */
public class WebQuiltLogEntry {

    //// -------------------------------------------------------
    ////  URL + Query variables
    ////

    public String    strReplace;  // the URL + query to go to
    public String    strBase;     // the base URL to go to
    public String    strOrig;     // the URL to go to
    public String    strQuery;    // the query string
    public String    strTarget;   // global target for links (if any)

    //// -------------------------------------------------------



    //// --------------------------------------------------------
    ////  WebQuilt Parameters
    ////

    public String  strLinkID;       // the link ID, ie the Nth link on the page
    public String  strTaskID;       // the task ID, a string identifying what the current task is
    public String  strUserID;       // the user ID, a string identifying the current user
    public String  strTaskBox;      // whether to turn on the task box ({float, bottom, off})
    public String  strTrackstring;  // whether to turn on the task box ({float, bottom, off})

    public int     fromTID;         // the value of the referrer TID
    public int     nextTID;         // the next transaction ID to use
    public int     parentID;        // the parent frames TID, or -1 if none
    public int     frameID;         // the frame ID, which frame in a frameset it is
    public int     numFrames;       // the number of frames, if this is a frameset


    public long    time;            // how much time the user spent on a page

    //// ---------------------------------------------------------



    //// ---------------------------------------------------------
    //// Connection variables - these specify data
    ////  about the current HTTP connection
    ////

    public int       respCode    = -1;     // the HTTP response code (e.g. 200, 404)
    public boolean   secure      = false;  // Is the client requesting a secure page?
    public boolean   isInterCard = false;  // indicates an intercard action
    public boolean   isPost      = false;  // assuming isWAP is false, this
                                           //  indicates HTTP request method. A true
                                           //  value indicates 'POST', otherwise 'GET'
    public String    contentType = "";     // the MIME type of the page

    //// ---------------------------------------------------------


    /**
     * Creates the String version of this LogEntry.
     *  This is the string that will be saved in the WebQuilt logfile.
     * @return the String representing this log entry
     *
     * trying chaning strOrig to strReplace to differentiate pages
     */
    public String toString() {
	String requestMethod;
	if (isInterCard)
		requestMethod = "INCARD   ";
	else
		requestMethod = ( isPost ? "POST  " : "GET   " );

	return ( time         + "\t" +
		 fromTID      + " "  +
		 nextTID      + "\t" +
		 parentID     + "\t" +
		 respCode     + " "  +
		 frameID      + "\t" +
		 strLinkID    + "\t" +
		 requestMethod +
		 strReplace    + "\t" +
		 strQuery   + "\n" );
    } //

    /**
     * Returns a debug string that is everything
     */
    public String toDebugString() {
	return ( "-----\nstrReplace: " + strReplace + "\n" +
		 "strBase: " + strBase + "\n" +
		 "strOrig: " + strOrig + "\n" +
		 "strQuery: " + strQuery + "\n" +
		 "strTarget: " + strTarget + "\n" +
		 "respCode: " + respCode + "\n" +
		 "secure: " + secure + "\n" +
		 "isPost: " + isPost + "\n" +
		 "isInterCard: " + isInterCard + "\n" +
		 "contentType: " + contentType + "\n-----\n");
    } // of method


    /**
     * Returns a header string which explains what the
     *  different log entrys signify.
     * @return the log header string
     */
    public static String getLogHeader() {
	return "Time From To  Parent  Code Frame Link  Method  URL + Query String";
    } //

} // of class
//==============================================================================

/*
Copyright (c) 2001 Regents of the University of California.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.

3. All advertising materials mentioning features or use of this software
   must display the following acknowledgement:

      This product includes software developed by the Group for User
      Interface Research at the University of California at Berkeley.

4. The name of the University may not be used to endorse or promote products
   derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
